﻿using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using System;

namespace TvGame
{
    class BloodDisplay
    {
        Texture2D texture;
        string selectedTexture;
        public double displayTime;
        Vector2 position;
        Random random;

        public bool IsVisible = true;

        public BloodDisplay(ContentManager content, Vector2 position, Texture2D texture, double displayTime)
        {
            selectedTexture = "blood2";
            texture = content.Load<Texture2D>("Sprites//" + selectedTexture);
            Reset(position, texture, displayTime);
            random = new Random();
        }

        public void Reset(Vector2 position, Texture2D texture, double displayTime)
        {
            this.position = position;            
            this.displayTime = displayTime;
            this.texture = texture;
            IsVisible = true;
        }

        public void Update(GameTime gameTime)
        {
            if (IsVisible)
            {
                displayTime -= gameTime.ElapsedGameTime.TotalMilliseconds / 30;
                if (displayTime <= 0)
                {
                    IsVisible = false;
                }                
            }
            
            int textureChance = random.Next(0, 3);

                if (textureChance == 1)
                {
                    selectedTexture = "blood";
                }
                if (textureChance == 2)
                {
                   // selectedTexture = "blood2";
                }
                if (textureChance == 3)
                {
                    selectedTexture = "blood3";
                }
        }

        public void Draw(SpriteBatch batch)
        {
            Vector2 shadowOffset = Vector2.One;

            if (IsVisible)
            {                
                batch.Draw(texture, position, null, Color.Red, 0f, new Vector2(texture.Width / 2, texture.Height / 2), 
                    1f, SpriteEffects.None, 0.7f);
            }
        }
    }
}